home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Graphics / VideoToolbox ƒ / VideoToolboxSources / HideMenuBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-07  |  4.1 KB  |  152 lines  |  [TEXT/KAHL]

  1. /*
  2. HideMenuBar.c
  3.  
  4. Based on:
  5.  
  6. "Code gadgets: Hiding the menu bar", THINKin' CaP, 1(2):28-29, Fall 1990.
  7. Copyright © 1991 SPLAsh Resources.
  8.  
  9. and
  10.  
  11. Symantec THINK Reference 2, "How to Hide the MenuBar".
  12.  
  13. NOTE:
  14. The use of the low-memory global MBarHeight cannot be replaced by Apple's
  15. GetMBarHeight() call because we need to write as well as read, and to
  16. my knowledge Apple hasn't yet provided any way of doing that other than
  17. poking into the low-memory global.
  18.  
  19. HISTORY:
  20. 2/28/91 dgp added to VideoToolbox
  21. 8/24/91    dgp    Made compatible with THINK C 5.
  22. 1/25/93 dgp removed obsolete support for THINK C 4.
  23. 1/25/93    dgp Replaced SysEqu.h by LoMem.h and changed program accordingly.
  24. 2/23/93    dgp    Call CopyQuickDrawGlobals to make sure qd is valid.
  25. 2/27/93    dgp Edited the code and comments, partly copying from THINK Reference's
  26.             suggestion for how to do this. This was prompted by David Brainard's
  27.             report that these routines were crashing when called within the
  28.             MATLAB environment. The main changes are to also call
  29.             CalcVisBehind() after restoring, and to use DiffRgn
  30.             to restore by cutting the menu bar back out of the desktop
  31.             instead of restoring by copying from a saved copy of the region. 
  32. 3/3/93    dgp    Added SquareCorners and RestoreCorners, with support for 1-bit quickdraw.
  33. */
  34. #include "VideoToolbox.h"
  35. #include <Menus.h>
  36. #if THINK_C
  37.     #include <LoMem.h>
  38. #else
  39.     short MBarHeight : 0xBAA;
  40. #endif
  41.  
  42. static short oldMBarHeight;                    // Pixel height of the menu bar
  43. static RgnHandle mBarRgn=NULL;                // Region encompassing the menu bar
  44. static RgnHandle cornerRgn[MAX_SCREENS];
  45.  
  46. void HideMenuBar(void)
  47. {
  48.     Rect r;
  49.     
  50.     if (MBarHeight>0) {
  51.         mBarRgn=NewRgn();
  52.         CopyQuickDrawGlobals();                // Make sure qd is valid
  53.         r=qd.screenBits.bounds;
  54.         r.bottom=r.top+MBarHeight;
  55.         RectRgn(mBarRgn,&r);
  56.         oldMBarHeight=MBarHeight;
  57.         MBarHeight=0;
  58.         UnionRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  59.         PaintOne(NULL,mBarRgn);
  60.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  61.     }
  62. }
  63.  
  64. void ShowMenuBar(void)
  65. {
  66.     if(MBarHeight==0 && mBarRgn!=NULL){
  67.         MBarHeight=oldMBarHeight;
  68.         DiffRgn(GetGrayRgn(),mBarRgn,GetGrayRgn());
  69.         DrawMenuBar();
  70.         CalcVisBehind((WindowPeek)FrontWindow(),mBarRgn);
  71.         DisposeRgn(mBarRgn);
  72.         mBarRgn=NULL;
  73.     }
  74. }
  75.  
  76. void SquareCorners(GDHandle device)
  77. // Extend GrayRgn to include this screen's corners, which otherwise might be rounded off.
  78. // If NULL then applies to all screens.
  79. {
  80.     int i;
  81.     Rect r;
  82.     long quickDraw;
  83.     
  84.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  85.     if(quickDraw<gestalt8BitQD){
  86.         i=0;
  87.         CopyQuickDrawGlobals();                // Make sure qd is valid
  88.         r=qd.screenBits.bounds;
  89.         r.top+=MBarHeight;
  90.     }else{
  91.         if(device==NULL){
  92.             for(i=0;GetScreenDevice(i)!=NULL;i++)SquareCorners(GetScreenDevice(i));
  93.             return;
  94.         }
  95.         i=GetScreenIndex(device);
  96.         if(i>=MAX_SCREENS)return;
  97.         r=(*device)->gdRect;
  98.         if(device==GetMainDevice())r.top+=MBarHeight;
  99.     }
  100.     cornerRgn[i]=NewRgn();
  101.     RectRgn(cornerRgn[i],&r);
  102.     DiffRgn(cornerRgn[i],GetGrayRgn(),cornerRgn[i]);
  103.     if(EmptyRgn(cornerRgn[i]))return;
  104.     UnionRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  105.     PaintBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  106.     CalcVisBehind((WindowPeek)FrontWindow(),cornerRgn[i]);
  107. }
  108.  
  109. void RestoreCorners(GDHandle device)
  110. // Restore rounding to this screen.
  111. // If NULL then applies to all screens.
  112. {
  113.     int i;
  114.     long quickDraw;
  115.     
  116.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  117.     if(quickDraw<gestalt8BitQD){
  118.         i=0;
  119.     }else{
  120.         if(device==NULL){
  121.             for(i=0;GetScreenDevice(i)!=NULL;i++)RestoreCorners(GetScreenDevice(i));
  122.             return;
  123.         }
  124.         i=GetScreenIndex(device);
  125.         if(i>=MAX_SCREENS)return;
  126.     }
  127.     if(cornerRgn[i]!=NULL){
  128. //        CopyQuickDrawGlobals();            // Make sure qd is valid.
  129. //        FillRgn(cornerRgn[i],(ConstPatternParam)&qd.black);    // don't know what port it belongs to
  130.         DiffRgn(GetGrayRgn(),cornerRgn[i],GetGrayRgn());
  131.         DisposeRgn(cornerRgn[i]);
  132.         cornerRgn[i]=NULL;
  133.     }
  134. }
  135.  
  136. void UnclipScreen(GDHandle device)
  137. {
  138.     long quickDraw;
  139.  
  140.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  141.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())HideMenuBar();
  142.     SquareCorners(device);
  143. }
  144.  
  145. void RestoreScreenClipping(GDHandle device)
  146. {
  147.     long quickDraw;
  148.  
  149.     RestoreCorners(device);
  150.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  151.     if(quickDraw<gestalt8BitQD || device==GetMainDevice())ShowMenuBar();
  152. }